package com.example.xyxwebbackend001.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.xyxwebbackend001.model.entity.Favorites;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FavoriteMapper extends BaseMapper<Favorites> {
    // 统计收藏总数（动态IN查询）
    @Select({
            "<script>",
            "SELECT COUNT(*) FROM t_favorites",
            "WHERE t_post_id IN",
            "<foreach item='id' collection='postIds' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    Integer sumFavoritesByPostIds(@Param("postIds") List<Integer> postIds);
}
